package com.njlime.member.repository.app;

import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.core.helper.PageBean;
import com.njlime.member.entiies.MemberComment;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Repository
public class AppMemberCommentDaoImpl extends BaseDaoImpl<MemberComment>{

    /**
     * 详情
     * @param id
     * @return
     */
    public Map<String, Object> get(int id) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_member_comment where id  = ?");
        arrList.add(id);
        List<Map<String, Object>> re = getListJdbc(sb.toString(), arrList);
        if (re != null && re.size() > 0) {
            return re.get(0);
        }
        return null;
    }

    /**
     * 删除收藏
     * @param id
     * @return
     */
    public int del(int id) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append(" UPDATE t_member_comment SET is_del = 1 WHERE id = ?");
        arrList.add(id);
        return updateJdbc(sb.toString(), arrList);
    }

    /**
     * 收藏列表
     * @param pageBean
     * @param info
     * @return
     */
    public PageBean list(PageBean pageBean, MemberComment info) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_member_comment ");
        sb.append("WHERE member_id = ?");
        arrList.add(info.getMember_id());
        int num = getListJdbcSize(sb.toString(), arrList);
        pageBean.setTotalCount(num);
        pageBean.setTotalPage(pageBean.getTotalPage());
        if (num > 0) {
            sb.append(" order by id desc limit ?,?");
            arrList.add((pageBean.getCurPage() - 1) * pageBean.getPageSize());
            arrList.add(pageBean.getPageSize());
            pageBean.setMapList(getListJdbc(sb.toString(), arrList));
        }
        return pageBean;
    }


}
